package com.miniboy.imageloader.config;

import com.miniboy.imageloader.R;

/**
 * 作者 ${郭鹏飞}.<br/>
 * <p/>
 * 通过{@link com.miniboy.imageloader.config.ImageOptions.ImageOptionsBuilder}类进行实例化
 */
public class ImageOptions {

    /**
     * 定义缓冲类型 不做缓冲
     */
    public static final int TYPE_NO_CACHE = 0x1000;
    /**
     * 定义缓冲类型 磁盘缓冲
     */
    public static final int TYPE_DISK_CACHE = 0x1001;
    /**
     * 定义缓冲类型 内存缓冲
     */
    public static final int TYPE_MEMORY_CACHE = 0x1002;
    /**
     * 定义缓冲类型 磁盘和内存都做缓冲
     */
    public static final int TYPE_ALL_CACHE = 0x1003;
    private static final int DEFAULT_DISK_CACHE_MAX_SIZE = 50 * 1024 * 1024;

    /**
     * 图片宽
     */
    public int mWidth;
    /**
     * 图片长
     */
    public int mHeight;
    /**
     * 磁盘缓存的大小
     */
    public int mDiskMaxSize = DEFAULT_DISK_CACHE_MAX_SIZE;
    /**
     * 缓存类型
     */
    public int mCacheType = TYPE_ALL_CACHE;
    /**
     * 占位图
     */
    public int mPlaceBitmapId = R.mipmap.ic_launcher;
    /**
     * 空地址显示的图片
     */
    public int mEmptyUrlBitmapId = R.mipmap.ic_launcher;
    /**
     * 下载失败显示的图片
     */
    public int mFailedBitmapId = R.mipmap.ic_launcher;
    /**
     * 没有网络显示的图片
     */
    public int mNoNetworkBitmapId = R.mipmap.ic_launcher;

    private ImageOptions() {
    }

    /**
     * 克隆一个和当前对象一样的对象
     *
     * @return ImageOptions
     */
    public ImageOptions clone() {
        ImageOptions imageOptions = new ImageOptions();
        imageOptions.mWidth = this.mWidth;
        imageOptions.mHeight = this.mHeight;
        imageOptions.mCacheType = this.mCacheType;
        imageOptions.mDiskMaxSize = this.mDiskMaxSize;
        imageOptions.mPlaceBitmapId = this.mPlaceBitmapId;
        imageOptions.mEmptyUrlBitmapId = this.mEmptyUrlBitmapId;
        imageOptions.mFailedBitmapId = this.mFailedBitmapId;
        imageOptions.mNoNetworkBitmapId = this.mNoNetworkBitmapId;
        return imageOptions;
    }

    public static final class ImageOptionsBuilder {

        private ImageOptions mImageOptions;

        public ImageOptionsBuilder() {
            mImageOptions = new ImageOptions();
        }

        public ImageOptionsBuilder reqWidth(int reqWidth) {
            mImageOptions.mWidth = reqWidth;
            return this;
        }

        public ImageOptionsBuilder reqHeight(int reqHeight) {
            mImageOptions.mHeight = reqHeight;
            return this;
        }

        public ImageOptionsBuilder type(int type) {
            mImageOptions.mCacheType = type;
            return this;
        }

        public ImageOptionsBuilder diskMaxSize(int size) {
            mImageOptions.mDiskMaxSize = size;
            return this;
        }

        public ImageOptionsBuilder placeBitmapId(int id) {
            mImageOptions.mPlaceBitmapId = id;
            return this;
        }

        public ImageOptionsBuilder emptyBitmapId(int id) {
            mImageOptions.mEmptyUrlBitmapId = id;
            return this;
        }

        public ImageOptionsBuilder failedBitmapId(int id) {
            mImageOptions.mFailedBitmapId = id;
            return this;
        }

        public ImageOptionsBuilder noNetworkBitmapId(int id) {
            mImageOptions.mNoNetworkBitmapId = id;
            return this;
        }

        public ImageOptions build() {
            return mImageOptions;
        }
    }

}
